package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bean.vo.PunishInfoVO;
import com.jishuo.nontax.bfc.service.PunishService;
import org.dom4j.Element;

import java.math.BigDecimal;

/**
 * 罚没滞纳金接口
 *
 * @auther dinggaofei
 * @Date 2023/2/9 10:38
 */
public class PunishLatefeeApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if (head.equals("getLatefee")) { // 获取滞纳金数据
            PunishInfoVO vo = new PunishInfoVO();
            vo.setPunishbillnum(body.elementText("punishbillnum"));
            vo.setUnitid(Long.parseLong(body.elementText("unitid")));
            vo.setBillyear(body.elementText("billyear"));
            vo.setPunishamt(new BigDecimal(body.elementText("punishamt")));
            vo.setPunishdate(body.elementText("punishdate"));
            vo.setPaybankdt(body.elementText("paybankdt"));
            vo.setIsremission(Integer.parseInt(body.elementText("isremission")));
            PunishService punishService = (PunishService) SpringContextUtil.getBean("punishService");
            return punishService.getLatefee(vo);
        } else if (head.equals("setPunishInfo")) { //银行代录罚没信息
            String xml = "";
            if (body.asXML() != null && body.asXML().trim().length() > 7) {
                xml = body.asXML().substring(6, body.asXML().length() - 7);
            }
            PunishService punishService = (PunishService) SpringContextUtil.getBean("punishService");
            BaseResult result = punishService.setPunishInfo(xml);
            //返回数据对象
            int n = (result.isSuccess()) ? 1 : 0;
            result.setData("<returninfo>" + n + "</returninfo>");
            return result;
        }
        return null;
    }
}
